/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bionic.ce.businesslogic;

import com.bionic.ce.dao.ICurrencyDAO;
import com.bionic.ce.beans.Currency;
import com.bionic.ce.connections.DAOFactory;
import java.sql.SQLException;
import java.util.List;

/**
 *
 * @author Jarik
 */
public class CurrencyService {

    public static ICurrencyDAO currencyDAO;

    static {
        DAOFactory factory = DAOFactory.getDAOFactory(DAOFactory.MYSQL);
        currencyDAO = factory.getCurrencyDAO();
    }

    public static void createNewCurrency(String shortName, String fullName, Integer code) {
        Currency currency = new Currency();
        currency.setShortName(shortName);
        currency.setShortName(shortName);
        currency.setCode(code);
        try {
            currencyDAO.add(currency);
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
    }

    public static void updateCurrentCurrency(String shortName, String fullName, Integer code) {
        Currency currency = new Currency();
        currency.setShortName(shortName);
        currency.setShortName(shortName);
        currency.setCode(code);
        try {
            currencyDAO.update(currency);
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
    }

    public static void deleteCurrentCurrency(String shortName) {
        try {
            currencyDAO.deleteByShortName(shortName);
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
    }

    public static Currency returnCurrentCurrencyInfo(String shortName) {
        Currency currency = new Currency();
        currency.setShortName(shortName);
        try {
            List<Currency> list = currencyDAO.findByDynamicSelect(currency);
            currency = ((Currency) list.toArray()[0]);
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        return currency;
    }

    public static List<Currency> findAllCurrency() {
        List<Currency> list=null;
        try {
            list = currencyDAO.findAll();
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        return list;
    }
}
